<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="test.php">
        <input type="submit" value="提交">
    </form>
    <a href="https://www.baidu.com">百度一下</a>
    <script>
        var input = document.querySelector('input');
        var a = document.querySelector('a');
        input.onclick = function () {
            // 取消提交按钮跳转行为 阻止事件默认行为
            event.preventDefault()
        }
        a.onclick = function () {
            event.preventDefault()
        }
    </script>
</body>

</html>